/**
 * @main.h
 * This file is part of FEGRF.
 * 
 * FEGRF is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * See LICENSE file in main folder for more information.
 */

#ifndef __MAIN_H__
#define __MAIN_H__

class MyDataViewCtrl;
class MyDataList;
class GRFFrame;

#include "libgrf/libgrf.h"
#include "libspr/spr.h"

#include <wx/dataview.h>
#include <wx/fileconf.h>
#include <wx/progdlg.h>
#include <wx/srchctrl.h>
#include <wx/thread.h>

#define CONFIG_FILENAME "config"

enum winID
{
	BTN_NEW = wxID_LAST + 1,
	BTN_OPEN,
	BTN_CLOSE,
	BTN_VIEW,
	BTN_REPACK,
	BTN_INSERT,
	BTN_EXTRACT,
	BTN_DELETE,
	BTN_SETTING,
	BTN_SAVE,
	BTN_BACK,
	BTN_NEXT,
	FILTER_TEXT,
	POP_EXTRACT_SELECTED,
	POP_EXTRACT_ALL,
	POP_VIEW,
	POP_DELETE,
	POP_RENAME,
	DIALOG_REPACK,
	DIALOG_EXTRACT,
	DIALOG_EXTRACT_ALL,
	DIALOG_EXTRACT_ERROR,
	DIALOG_INSERT,
	DIALOG_LIST,
	DIALOG_SETTING,
	DIALOG_BTN_REPACK,
	DIALOG_BTN_EXTRACT,
	DIALOG_BTN_CANCEL,
	DIALOG_BTN_INSERT_GRF,
	DIALOG_BTN_INSERT_DIR,
	DIALOG_BTN_SETTING,
	CHECK_BOX_DIR,
	CHECK_BOX_ASCII,
	LIST_GRF,
	FRAME_VIEW,
};

class MyApp : public wxApp
{
public:
	virtual bool OnInit();
};

class MainFrame : public wxFrame
{
public:
	MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
	~MainFrame();

	GrfFile          *m_grf_handle;
	wxString          m_grf_path;
	MyDataViewCtrl   *m_grf_list;
	MyDataList       *m_grf_data;
	wxMenu           *m_pop_menu;
	wxSearchCtrl     *m_filter;
	wxToolBar        *m_toolbar;
	wxFileConfig     *m_config;
	GRFFrame         *m_view;
	bool              m_read_only;
	wxProgressDialog *m_progress;

	void OnToolbarNew(wxCommandEvent &event);
	void OnToolbarOpen(wxCommandEvent &event);
	void OnToolbarClose(wxCommandEvent &event);
	void OnToolbarFilter(wxCommandEvent &event);
	void OnToolbarView(wxCommandEvent &event);
	void OnToolbarRepack(wxCommandEvent &event);
	void OnToolbarInsert(wxCommandEvent &event);
	void OnToolbarExtract(wxCommandEvent &event);
	void OnToolbarDelete(wxCommandEvent &event);
	void OnToolbarSetting(wxCommandEvent &event);
	void ToolbarEnable(bool enable);
	void OnListDClick(wxDataViewEvent &event);
	void OnPopMenu(wxDataViewEvent &event);
	void OnPopRename(wxCommandEvent &event);
	void OnPopView(wxCommandEvent &event);
	void OnPopExtract(wxCommandEvent &event);
	void OnPopExtractAll(wxCommandEvent &event);
	void OnPopDelete(wxCommandEvent &event);
	void OnKeyPressed(wxKeyEvent &event);
	void OnCloseWindow(wxCloseEvent &event);
	void OnExtract();
	void OnDelete();
	void GRFRead();
	void GRFClose();
	bool FileNew(const wxString &file_path);
	bool FileOpen(const wxString &file_path);
	void FileFilter();
	void FileView();
	void FileInsert(int flag);
	void FileRepack(int flag);
	bool FileExtract(GrfNode *node, wxString path, int flag);
	void DialogExtract();
	void DialogDelete();
	void DialogSetting();
	void SettingsLoad();
	void SettingsSave();
	void DataClear();
private:
	DECLARE_EVENT_TABLE()
};

class WorkerThread : public wxThread
{
public:
	WorkerThread(MainFrame *frame, int flag);
	
	MainFrame *m_frame;
	int        m_flag;

	virtual ExitCode Entry();
};

wxString GetExtension(const char *filename);
wxString ConvertByte(uint64_t size_real, uint64_t size_compressed = 0);

#endif //__MAIN_H__
